package untils

import (
	"time"
	"strconv"
	"fmt"
)

func GetChildAge(yearStr, monthStr, dayStr string) string {
	age := "年龄异常"
	if yearStr == "" || monthStr == "" || dayStr == "" {
		return age
	}

	// 获得当前的年月日
	Nowyear := time.Now().Year()
	Nowmonth := time.Now().Month()
	Nowday := time.Now().Day()
	// 转化年月日为int
	// todo 错误判断
	year, _ := strconv.Atoi(yearStr)
	month, _ := strconv.Atoi(monthStr)
	day, _ := strconv.Atoi(dayStr)
	//计算
	Y := (((int(Nowyear) * 12) + int(Nowmonth)) - ((year * 12) + month)) / 12
	M := (((int(Nowyear) * 12) + int(Nowmonth)) - ((year * 12) + month)) % 12
	// 不满一个月
	if Nowday-day < 0 {
		M = M - 1
		if M == -1 {
			Y = Y - 1
			M = 11
		}
	}
	age = fmt.Sprint(Y, `岁`, M, `个月`)
	return age
}

func GetchildGrade(grade string) string {
	gradeStr := "未设置"
	if grade != "" && grade != "-1" {
		if grade == "0" {
			gradeStr = "学前"
		} else {
			gradeStr = fmt.Sprint(grade, "年级")
		}
	}
	return gradeStr
}
